import {Injectable} from '@angular/core';

@Injectable()
export class ProductService {

  private products = [
    new Product(1, '合法化后', 4.5, 2.3, '大范甘迪', ['vdfv', 'gfsg']),
    new Product(2, 'df部分蛋糕fbf', 4.5, 2.3, '经历了居民， ', ['VCv', '肥嘟嘟']),
    new Product(3, 'df那你fbcf', 4.5, 4.3, '成都市发错地方', ['vdfv', '很快会尽快']),
    new Product(4, '通集团', 4.5, 2.3, '小沙发', ['发给', 'gfsg']),
    new Product(5, 'v过得很好', 4.5, 1.3, 'v更好地很有用', ['发']),
    new Product(6, '大发发', 4.5, 2.3, '公司公司分管', ['地方', 'gfsg'])
  ];

  private comments = [
    new Comment(1, 1, new Date(), 'tom', 3, 'good'),
    new Comment(2, 1, new Date(), 'bob', 3, 'good'),
    new Comment(3, 2, new Date(), 'john', 2, 'bad'),
    new Comment(4, 1, new Date(), 'sara', 4, 'so good'),
  ];

  getProducts() {
    return this.products;
  }

  getProduct(id) {
    return this.products.find(product => product.id == id);
  }

  getCommentsByProductId(productId: number) {
    return this.comments.filter(comment => comment.productId == productId);
  }

}

export class Product {
  constructor(public id: number,
              public title: string,
              public price: number,
              public rating: number,
              public desc: string,
              public categories: string[]) {

  }
}

export class Comment {
  constructor(public id: number,
              public  productId: number,
              public time: Date,
              public user: string,
              public rating: number,
              public content: string) {

  }
}
